﻿using System;
using EmbeddedSharp.Core;

namespace EmbeddedSharp.Scripting.Visualization.Functions
{
    /// <summary>
    /// Save current screen as an image
    /// </summary>
    [Function("saveImage", "Save current screen as an image.", "saveImage(\"c:\\demo.png\");", "")]
    public class SaveImageNode : VisualizationContextFuncNode
    {
        public SaveImageNode()
            : base()
        {
            base.Value = "saveImage";
        }

        public override object Evaluate()
        {
            if (Parameters.Count < 1)
            {
                throw new Exception("usage: saveImage(fileName)");
            }

            string fileName = Convert.ToString(Parameters[0].Evaluate());
            Provider.SaveImage(fileName);

            return string.Empty;
        }
    }
}
